
#include "galaxy.h"


Galaxy::Galaxy()
{
  // init random seed
  srand(time(NULL));
}

Galaxy::~Galaxy()
{

}

void		Galaxy::generate()
{
  int		galaxySize;

  for(galaxySize = 0; galaxySize < GALAXY_MIN_SIZE;)
    {
      galaxySize = (rand() % GALAXY_MAX_SIZE);
      std::cout << "galaxy size = " << galaxySize << std::endl;
    }
  generate(galaxySize);
}

void		Galaxy::generate(int galaxySize)
{
  SolarSystem	*newSys;
  int		i;

  std::cout << "Start creation of galaxy with " << galaxySize
	    << " stars" << std::endl;
  for(i = 0; i < galaxySize; i++)
    {
      newSys = new(SolarSystem);
      genRandCoor(newSys);
      newSys->setSolSysId(solarSysList.size());
      solarSysList.push_back(newSys);
    }
}

int		Galaxy::createLinks(int nbLinks)
{
  // need implementation
  return(0);
}

int		Galaxy::getGalaxySize()
{
  return(solarSysList.size());
}

SolarSystem	*Galaxy::getSolarSystem(int solarSysId)
{
  return(solarSysList.at(solarSysId));
}

void		Galaxy::genRandCoor(SolarSystem *newSys)
{
  int		xcord;
  int		ycord;
  int		zcord;

  if(rand() % 2 == 0)
    xcord = -(rand() % GALAXY_CUBE_SIZE);
  else
    xcord = rand() % GALAXY_CUBE_SIZE;

  if(rand() % 2 == 0)
    ycord = -(rand() % GALAXY_CUBE_SIZE);
  else
    ycord = rand() % GALAXY_CUBE_SIZE;

   if(rand() % 2 == 0)
    zcord = -(rand() % GALAXY_CUBE_SIZE);
  else
    zcord = rand() % GALAXY_CUBE_SIZE;

   newSys->generate(xcord, ycord, zcord);
}
